﻿using Kooboo.CMS.Common;
using Kooboo.CMS.Common.Runtime.Dependency;
using Kooboo.CMS.Content.Models.Binder;
using Kooboo.CMS.Content.Persistence;
using Kooboo.CMS.Content.Services;
using Kooboo.Globalization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Kooboo.Extensions.DeleteContentPermission.Controllers
{
    [Kooboo.CMS.Web.Authorizations.Authorization(AreaName = "Contents", Group = "", Name = "Content", Order = 1)]
    [ValidateInput(false)]
    [Dependency(typeof(Kooboo.CMS.Web.Areas.Contents.Controllers.TextContentController))]
    public class TextContentController : Kooboo.CMS.Web.Areas.Contents.Controllers.TextContentController
    {
        #region .ctor
        public TextContentController(TextContentManager textContentManager, TextFolderManager textFolderManager, WorkflowManager workflowManager, ITextContentBinder binder, ITextContentProvider textContentProvider)
            : base(textContentManager, textFolderManager, workflowManager, binder, textContentProvider)
        {
        }
        #endregion

        [Kooboo.CMS.Web.Authorizations.Authorization(AreaName = "Contents", Group = "", Name = "Content", Order = 1)]
        public override ActionResult Delete(string folderName, string parentFolder, string[] folders, string[] docs)
        {
            var userName = HttpContext.User.Identity.Name;
            if (Kooboo.CMS.Sites.Services.ServiceFactory.UserManager.Authorize(Kooboo.CMS.Sites.Models.Site.Current, userName, CustomerPermissions.ContentDelete))
            {
                return base.Delete(folderName, parentFolder, folders, docs);
            }
            else
            {
                var data = new JsonResultData(ModelState);
                data.AddErrorMessage("You have no permissions".Localize());
                return Json(data);
            }
        }
    }
}
